home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Lib / tai / tai_tb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  3.4 KB  |  163 lines

  1. /* tai_tb.c: table tailoring info */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Lib/tai/RCS/tai_tb.c,v 6.0 1991/12/18 20:24:59 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Lib/tai/RCS/tai_tb.c,v 6.0 1991/12/18 20:24:59 jpo Rel $
  9.  *
  10.  * $Log: tai_tb.c,v $
  11.  * Revision 6.0  1991/12/18  20:24:59  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include "retcode.h"
  20. #include <isode/cmd_srch.h>
  21. #include "table.h"
  22.  
  23.  
  24. extern void    err_abrt ();
  25. extern void    tai_error ();
  26.  
  27. static int    tb_numtables = 0;
  28. static int    tb_maxtb;
  29. static char    tbl_str[] = "tbl";
  30.  
  31. #define CMDTNAME        1
  32. #define CMDTFILE        2
  33. #define CMDTSHOW        3
  34. #define CMDTFLAGS       4
  35. #define CMDTOVER    5
  36.  
  37. static  CMD_TABLE tb_cmdtbl[] = {
  38.     "file",         CMDTFILE,
  39.     "flags",        CMDTFLAGS,
  40.     "name",         CMDTNAME,
  41.     "override",    CMDTOVER,
  42.     "show",         CMDTSHOW,
  43.     0,              -1
  44. };
  45. #define N_TBCMDS    ((sizeof(tb_cmdtbl)/sizeof(CMD_TABLE))-1)
  46.  
  47.  
  48. #define CMDTFLINEAR     1
  49. #define CMDTFDBM        2
  50.  
  51.  
  52. static  CMD_TABLE tb_flags[] = {
  53.     "linear",       CMDTFLINEAR,
  54.     "dbm",          CMDTFDBM,
  55.     0,              -1
  56. };
  57.  
  58.  
  59.  
  60. /* ---------------------  Begin  Routines  -------------------------------- */
  61.  
  62.  
  63.  
  64. int tbl_tai (argc, argv)
  65. int     argc;
  66. char    **argv;
  67. {
  68.     register Table  *tbptr;
  69.     char            *p,
  70.             *arg;
  71.     int             ind;
  72.  
  73.     if (argc < 2 || lexequ (argv[0], tbl_str) != 0)
  74.         return (NOTOK);
  75.  
  76.         if (tb_maxtb == 0) {
  77.                 tb_maxtb = 10;
  78.                 tb_all = (Table **)smalloc (sizeof(Table *) * tb_maxtb);
  79.         }
  80.         else if (tb_numtables + 1 == tb_maxtb) {
  81.                 tb_maxtb += 10;
  82.                 tb_all = (Table **) realloc ((char *)tb_all,
  83.                          (unsigned)sizeof (Table *) * tb_maxtb);
  84.                 if (tb_all == NULL)
  85.                         err_abrt (RP_MECH, "Out of space for tables");
  86.         }
  87.  
  88.  
  89.     argc--;
  90.     arg = *++argv;
  91.     tb_all[tb_numtables++] = tbptr = (Table *) smalloc (sizeof (Table));
  92.     tb_all [tb_numtables]   = NULLTBL;
  93.     tbptr -> tb_name        = arg;
  94.     tbptr -> tb_show        = arg;
  95.     tbptr -> tb_file        = arg;
  96.     tbptr -> tb_fp          = NULLFILE;
  97.     tbptr -> tb_flags       = TB_DBM;
  98.     tbptr -> tb_override    = NULL;
  99.     argv++;
  100.     argc--;
  101.  
  102.     for (ind = 0 ; ind < argc ; ind++) {
  103.  
  104.         if ((p = index (argv[ind], '=')) == NULLCP)
  105.             continue;
  106.         *p++ = '\0';
  107.  
  108.         switch (cmdbsrch (argv[ind], tb_cmdtbl, N_TBCMDS)) {
  109.             case CMDTNAME:
  110.             tbptr->tb_name = p;
  111.             break;
  112.             case CMDTFILE:
  113.             tbptr->tb_file = p;
  114.             break;
  115.             case CMDTSHOW:
  116.             tbptr->tb_show = p;
  117.             break;
  118.             case CMDTFLAGS:
  119.             switch (cmd_srch (p, tb_flags)) {
  120.                 case CMDTFDBM:
  121.                 tbptr->tb_flags = TB_DBM;
  122.                 break;
  123.                 case CMDTFLINEAR:
  124.                 tbptr->tb_flags = TB_LINEAR;
  125.                 break;
  126.                 default:
  127.                 tai_error ("Unknown flag %s for %s",
  128.                        p, tbptr -> tb_name);
  129.                 break;
  130.             }
  131.             break;
  132.             case CMDTOVER:
  133.             {
  134.                 char *cp;
  135.                 TableOverride *to, **tp;
  136.  
  137.                 if ((cp = index(p, ':')) == NULL)
  138.                     tai_error ("Illegal override syntax '%s' for %s",
  139.                            p, tbptr -> tb_name);
  140.                 else {
  141.                     *cp++ = '\0';
  142.                     to = (TableOverride *)
  143.                         smalloc (sizeof *to);
  144.                     to -> tbo_key = p;
  145.                     to -> tbo_value = cp;
  146.                     to -> tbo_next = NULL;
  147.                     for (tp = &tbptr -> tb_override;
  148.                          *tp; tp = &(*tp) -> tbo_next)
  149.                         continue;
  150.                     *tp = to;
  151.                 }
  152.             }
  153.             break;
  154.  
  155.             default:
  156.             tai_error ("unknown key %s for table %s",
  157.                    argv[ind], tbptr -> tb_name);
  158.             break;
  159.         }
  160.     }
  161.     return (OK);
  162. }
  163.